﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GraphLibrary
{
    class List<T>
    {
        Node _head; 

        public void Add(T value)
        {
            Node n = new Node(value);
            if (_head == null)
                _head = n;
            else
            {
                n.Next = _head;
                _head = n;
            }
        }

        public Node Find(T value)
        {
            Node n = _head;
            while ((n != null) && (n.Value.Equals(value)))
            {
                n = n.Next;
            }
            return n;
        }

        public void Delete(Node node)
        {
            Node n=_head;
            while ((n!=null) && (n.Next != node))
            {
                n = n.Next;
            }
            if (n != null)
            {
                n.Next = n.Next.Next;
            }
        }

        public class Node
        {
            public T Value { get; set; }
            public Node Next { get; set; }

            public Node(T value)
            {
                Value = value;
            }
        }

    }
}
